import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { OrderService } from '../../../../providers/order-service';
import { AuthService } from '../../../../providers/auth-service';



@Component({
  selector: 'page-order-comment',
  templateUrl: 'comment.html'
})

export class OrderCommentPage {
  order:any
  currentUser: any
  comments=[]
  content:any
  constructor(
     public orderService: OrderService,
     public navCtrl: NavController,
     public auth: AuthService,
     public param: NavParams
    ) { 
      this.currentUser  = auth.getUserInfo()
      this.order =  param.get('order')
      this.loadCommemt()
    }
    public loadCommemt() {
      this.orderService.loadCommemt(this.order.id).then(data => this.comments = data)
    }
    public commentOrder() {
      if (!this.content || this.content == ''){
        return
      }
      this.orderService.commentOrder({
        user_id: this.currentUser.user.id,
        content: this.content,
        order_id: this.order.id
      }).then(() => {
        this.content = null 
        this.loadCommemt()
      })
    }
}
